home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
007
/
cstdio.arc
/
SRC.ARC
/
SETARGS.C
< prev
next >
Wrap
C/C++ Source or Header
|
1985-10-14
|
2KB
|
113 lines
/* _setargs.c - set arguments from command string.
(C) Copyright 1984, 1985 Gregory R. Mansfield - All Rights Reserved.
G. R. Mansfield. 84/11/05.
Ver 1.1-5A14.
*/
#include <defstd.h>
#include <ctypem.h>
/* local functions */
static int glf();
int _setargs(ast, apt, s)
/* returns argc */
char *s; /* command string */
char **apt; /* argument pointer table same as *argv[] */
char *ast; /* argument strings */
{
char **apti;
int n, nx, wm, ws;
apti = apt;
*apt++ = ast; /* enter zero th argument */
*ast++ = '*';
*ast++ = '\0';
n = 1;
while (*s) {
while (*s == ' ') /* skip spaces between arguments */
s++;
nx = wm = ws = 0; /* copy argument noting wildcard characters */
*apt = ast;
while (*s && *s != ' ') {
if (*s == '*')
wm++;
if (*s == '?')
ws++;
if (*s == '.')
nx++;
*ast++ = *s++;
}
if (ast > *apt) {
*ast++ = '\0';
if (wm + ws) { /* expand wild card file names */
if (wm && !nx) {
ast--;
*ast++ = '.';
*ast++ = '*';
*ast++ = '\0';
}
apt += glf(*apt, apt, *apt);
ast = *apt;
}
else
apt++;
}
}
*apt = ast;
return(apt - apti);
}
static int glf(wn, fp, fnt) /* get list of files */
char **fp, *fnt, *wn;
{
struct msstat {
BYTE st_attr;
long st_ct;
long st_size;
char st_name[13];
};
struct msb_s {
BYTE res[21];
struct msstat st;
} msb;
char *fnti, **fpi, *p, pn[65];
int gap, i, j, n;
fnti = fnt;
fpi = fp;
i = msfmf(wn, 0x17, &msb); /* get first entry */
for (p = pn; *wn; wn++) /* prepare path name */
*p++ = tolower(*wn);
while (p > pn && *(p-1) != '/' && *(p-1) != '\\' && *(p-1) != ':')
p--;
*p = '\0';
while (!i) {
if (*msb.st.st_name != '.') { /* add name if not a directory */
n++;
*fpi++ = fnt;
for (p = pn; *p; p++) /* copy path name */
*fnt++ = *p;
for (p = msb.st.st_name; *p; p++) /* add file name */
*fnt++ = tolower(*p);
*fnt++ = '\0';
}
i = msfnf();
}
*fpi = fnt; /* terminate list */
n = fpi - fp;
for (gap = n/2; gap > 0; gap /= 2) { /* sort list pointers */
for (i = gap; i < n; i++) {
for (j = i-gap; j >= 0; j -= gap) {
if (strcmp(fp[j], fp[j+gap]) <= 0)
break;
fpi = fp[j];
fp[j] = fp[j+gap];
fp[j+gap] = fpi;
}
}
}
return(n);
}